#pragma once

#include <opencv2/opencv.hpp> 
using namespace cv;
 
std::string light_and_contrast_win_name = "亮度对比调整";
/// <summary>
/// 滚动条控制图像  亮度
/// </summary>
/// <param name="b"></param>
/// <param name="userdata"></param>
static void on_track_lightness(int b, void* userdata)
{
	// 获得void* 原图地址  则需要先把 指向void的指针void*转为 指向Mat的指针Mat*  ，随后从指针Mat*取值获得image的实际的Mat格式数据
	Mat image = *((Mat*)userdata);
	Mat dst = Mat::zeros(image.size(), image.type());
	Mat m = Mat::zeros(image.size(), image.type());
	m = Scalar(b, b, b);
	addWeighted(image, 1.0, m, 0, b, dst);
	imshow(light_and_contrast_win_name, dst);
}
/// <summary>
/// 滚动条控制图像  对比度
/// </summary>
/// <param name="b"></param>
/// <param name="userdata"></param>
static void on_track_contrast(int b, void* userdata)
{
	Mat image = *((Mat*)userdata);
	Mat dst = Mat::zeros(image.size(), image.type());
	Mat m = Mat::zeros(image.size(), image.type());
	double contrast = b / 100.0;
	addWeighted(image, contrast, m, 0, 0, dst);
	imshow(light_and_contrast_win_name, dst);
}
/// <summary>
///  滚动传参
/// </summary>
/// <param name="image"></param>
void tracking_bar_demo(Mat& image)
{
	namedWindow(light_and_contrast_win_name, WINDOW_AUTOSIZE);
	int maxLightness = 100;
	int lightness = 50;

	int maxContrast = 200;
	int contrast = 100;

	createTrackbar("Light Bar : ", light_and_contrast_win_name, &lightness, maxLightness, on_track_lightness, (void*)(&image));
	createTrackbar("Contrast Bar : ", light_and_contrast_win_name, &contrast, maxContrast, on_track_contrast, (void*)(&image));
	//on_track_lightness(50, &image);
	//on_track_contrast(60, &image);


}
